package com.imooc.user.mapper;

import com.imooc.thrift.user.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author LiJian
 * @date 2022/10/20
 */
@Mapper
public interface UserMapper {
    @Select("select id,username, password, real_name as realName," +
            "mobile, email from pe_user where id=#{id}")
    UserInfo getUserById(@Param("id") int id);

    @Select("select id,username, password, real_name as realName," +
            "mobile, email from pe_user where username=#{username}")
    UserInfo getUserByName(@Param("username") String username);

    @Insert("insert into pe_user (username, password, real_name, mobile, email)" +
            "values (#{u.username}, #{u.password}, #{u.realName}, #{u.mobile}, #{u.email})")
    void registerUser(@Param("u") UserInfo userInfo);

    @Select("SELECT u.id,u.username,u.`password`,u.real_name AS realName,u.mobile,u.email,t.intro,t.stars \n" +
            "FROM pe_user u INNER JOIN pe_teacher t ON t.user_id = u.id \n" +
            "where u.id=#{id}")
    UserInfo getTeacherById(@Param("id") int id);
}
